package com.atguigu.serviceedu.controller.front;

import com.atguigu.commonutils.R;
import com.atguigu.serviceedu.entity.EduCourse;
import com.atguigu.serviceedu.entity.EduTeacher;
import com.atguigu.serviceedu.service.EduCourseService;
import com.atguigu.serviceedu.service.EduTeacherService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;


@RestController
@RequestMapping("/serviceedu/front/teacher")
//@CrossOrigin
public class IndexTeacherFrontController {
    @Autowired
    private EduTeacherService teacherService;

    @Autowired
    private EduCourseService courseService;

    @ApiOperation(value = "分页讲师列表")
    @GetMapping(value = "getTeacherPageList/{page}/{limit}")
    public R pageList(
            @ApiParam(name = "page", value = "当前页码", required = true)
            @PathVariable Long page,

            @ApiParam(name = "limit", value = "每页记录数", required = true)
            @PathVariable Long limit) {

        Page<EduTeacher> pageParam = new Page<EduTeacher>(page, limit);

        Map<String, Object> map = teacherService.pageListWeb(pageParam);

        return R.ok().data(map);
    }
    @ApiOperation(value = "根据teacherId查询名师的详细信息以及课程")
    @GetMapping(value = "getTeacherInfoByTeacherId/{teacherId}")
    public R getTeacherInfoByTeacherId(@PathVariable("teacherId")String teacherId){
        EduTeacher teacher = teacherService.getById(teacherId);

        List<EduCourse> courseList=courseService.getTeacherCourseList(teacherId);
        return R.ok().data("teacher",teacher).data("courseList", courseList);
    }
}
